package com.crm.jdy.controller.ceshi;//package com.crm.jdy.handler;
//
//import com.crm.jdy.common.utils.api.ResultVo;
//import com.fasterxml.jackson.databind.JsonMappingException;
//import com.fasterxml.jackson.databind.exc.InvalidFormatException;
//import org.hibernate.validator.internal.engine.path.PathImpl;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.converter.HttpMessageNotReadableException;
//import org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.ResponseStatus;
//
//import javax.validation.ConstraintViolation;
//import javax.validation.ConstraintViolationException;
//import javax.validation.ValidationException;
//import java.util.List;
//import java.util.Set;
//
//@ResponseBody
//@ControllerAdvice
//public class ExceptionAdvice {
//    private static Logger logger = LoggerFactory.getLogger(ExceptionAdvice.class);
//    /*** * 参数绑定异常 * @date 2020/08/14 * @param exception HttpMessageNotReadableException */
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
//    @ExceptionHandler(HttpMessageNotReadableException.class)
//    public ResultVo messageNotReadable(HttpMessageNotReadableException exception){
//     InvalidFormatException formatException = (InvalidFormatException)exception.getCause();
//     List<JsonMappingException.Reference> e = formatException.getPath();
//     String fieldName = "";
//    for (JsonMappingException.Reference reference :e){
////        String fieldName = reference.getFieldName();
//    }
//    logger.error("参数不匹配"+exception);
//    return ResultVo.failed(fieldName+"参数类型不匹配");
//    } /*** * 全局异常，如果没有匹配到上述准确的异常，都会到这里来处理 * @date 2020/08/14 * @param e 没有匹配到的全局异常 */
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
//    @ExceptionHandler(Exception.class)
//    public ResultVo all(Exception e){
//        //异常信打印出来，定位bug logger.error("异常：",e);
//        return ResultVo.failed(e.getMessage());
//    }

////    @ResponseStatus(HttpStatus.BAD_REQUEST)
////    @ExceptionHandler(Exception.class)
////    public ResultVo all(Exception index) {
////
////        return ResultVo.failed(index.getMessage(),"2525");
////    }
//
//
//     @ResponseStatus(HttpStatus.BAD_REQUEST)
//     @ExceptionHandler(Exception.class)
//     public ResultVo Exception(Exception e) {
//          if (e instanceof IllegalStateException) {
//             return ResultVo.failed( e.getMessage(),"4010");
//           } else if (e instanceof MethodArgumentNotValidException) {
//            return ResultVo.failed(e.getMessage());
//          }
//           return   ResultVo.failed(e.getMessage());
//     }
//
//  }
//
